package co.fitstart.entity.market.template;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.OrderBy;
import org.hibernate.annotations.Where;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.market.MarketCourse;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "market_monthly_courseware_template")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class MarketMonthlyCoursewareTemplate {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 名称 */
    private String name;
    
    /** 顺序 */
    private int sorting;
    
    /** 描述 */
    private String description;
    
    /** 周数 */
    private int weeks;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private MarketCourse course;
    
    @OneToMany(mappedBy = "monthly", fetch = FetchType.LAZY)
    @Where(clause = "is_disabled = 0")
    @OrderBy(clause = "sorting ASC")
    @JSONField(serialize = false)
    private List<MarketBatchCoursewareTemplate> batchCoursewares;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public MarketMonthlyCoursewareTemplate() {
        
    }
    
    /**
     * 
     * @param name
     * @param sorting
     * @param description
     * @param weeks
     * @param course
     */
    public MarketMonthlyCoursewareTemplate(String name, int sorting, String description, int weeks, MarketCourse course) {
        this.name = name;
        this.sorting = sorting;
        this.description = description;
        this.weeks = weeks;
        this.course = course;
        this.disabled = false;
    }
    
    /**
     * 
     * @param name
     * @return
     */
    public MarketMonthlyCoursewareTemplate editName(String name) {
        this.name = name;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public String getSortingName() {
        String[] num = {"一","二","三","四"};
        return "第" + num[sorting-1] + "阶段";
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the sorting
     */
    public int getSorting() {
        return sorting;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @return the weeks
     */
    public int getWeeks() {
        return weeks;
    }

    /**
     * @return the course
     */
    public MarketCourse getCourse() {
        return course;
    }

    /**
     * @return the batchCoursewares
     */
    public List<MarketBatchCoursewareTemplate> getBatchCoursewares() {
        return batchCoursewares;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param sorting the sorting to set
     */
    public void setSorting(int sorting) {
        this.sorting = sorting;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @param weeks the weeks to set
     */
    public void setWeeks(int weeks) {
        this.weeks = weeks;
    }

    /**
     * @param course the course to set
     */
    public void setCourse(MarketCourse course) {
        this.course = course;
    }

    /**
     * @param batchCoursewares the batchCoursewares to set
     */
    public void setBatchCoursewares(List<MarketBatchCoursewareTemplate> batchCoursewares) {
        this.batchCoursewares = batchCoursewares;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
